import Flutter
import MediaPlayer

public class IosMediaLibraryPermissionPlugin: NSObject, FlutterPlugin {
  public static func register(with registrar: FlutterPluginRegistrar) {
    let channel = FlutterMethodChannel(name: "ios_media_library_permission", binaryMessenger: registrar.messenger())
    let instance = IosMediaLibraryPermissionPlugin()
    registrar.addMethodCallDelegate(instance, channel: channel)
  }

   public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
     switch call.method {
     case "getMediaLibraryPermission":
       result(MPMediaLibrary.authorizationStatus().rawValue)
     case "requestMediaLibraryPermission":
          MPMediaLibrary.requestAuthorization { (status) -> Void in
                     if status == .authorized {
                         result(true)
                     } else {
                         result(false)
                     }
                 }
     default:
       result(FlutterMethodNotImplemented)
     }
   }
}
